package org.csu.onlineedubackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.csu.onlineedubackend.entity.CourseSubscribe;

import java.util.List;
import java.util.Map;

/**
 * 课程订阅Mapper接口
 */
@Mapper
public interface CourseSubscribeMapper extends BaseMapper<CourseSubscribe> {
    // 继承了BaseMapper，已经包含了基本的CRUD方法

    /**
     * 獲取學生訂閱的所有課程
     * @param userId 學生ID
     * @return 課程列表
     */
    @Select("SELECT c.id, c.title as name, c.cover_url as image FROM course c " +
            "JOIN course_subscribe cs ON c.id = cs.course_id " +
            "WHERE cs.student_id = #{userId}")
    List<Map<String, Object>> getSubscribedCoursesByUserId(Long userId);

    // 获取课程的订阅量
    @Select("SELECT COUNT(*) FROM course_subscribe WHERE course_id = #{courseId}")
    int countByCourseId(@Param("courseId") Integer courseId);
}